/**
 * 试吃申请 商品tree
 * 
 * @param {}
 *            id
 * @param {}
 *            title
 * @return {}
 */
var saveCompanyApplyEatTreeWin = function(id, title) {
	var b = new Ext.ux.TreeCheckPanel({
		id : "companyApplyEatVillageView",
		// checkModel : 'cascade', // 对树的级联多选
		onlyLeafCheckable : true,// 对树所有结点都可选
		autoScroll : true,
		rootVisible : false,
		animate : false,
		lines : true,
		checkModel : 'single',
		loader : new Ext.ux.TreeCheckLoader({
			dataUrl : __ctxPath
					+ "/couponRuleManager/selectGoodsTree?goodsStatus=1&isDelete=0",
			preloadChildren : true
		}),
		root : new Ext.tree.AsyncTreeNode({
					expanded : true
				}),
		tbar : [{
					xtype : "button",
					text : "展开",
					iconCls : "btn-expand",
					scope : this,
					handler : function() {
						b.expandAll();
					}
				}, {
					xtype : "tbseparator"
				}, {
					xtype : "button",
					text : "收起",
					iconCls : "btn-collapse",
					scope : this,
					handler : function() {
						b.collapseAll();
					}
				}, {
					xtype : "tbseparator"
				}, "->", {
					id : "refresh",
					xtype : "button",
					text : "刷新",
					iconCls : "btn-refresh",
					handler : function() {
						b.getRootNode().reload();
					}
				}]
	});
	b.expandAll();
	var companyEatApplyOrderForm = new Ext.form.FormPanel({
				id : 'companyEatApplyOrderForm',
				frame : true,
				buttonAlign : 'center',
				monitorValid : true,
				bodyBorder : false,
				labelWidth : 70,
				items : [{
					layout : 'form',
					border : false,
					style : {
						"textAlign" : 'center'
					},
					items : [{
						xtype : 'compositefield',
						fieldLabel : "<span style='color:#F00'>*</span>配送日期",
						combineErrors : false,
						items : [{
									id : 'companyEatApplyOrder_deliveryDate',
									xtype : 'datefield',
									name : "deliveryDate",
									allowBlank : false,
									blankText : "配送日期不能为空!",
									format : "Y-m-d",// 日期的格式
									width : 150,
									minValue : new Date(),
									editable : false
								}, {
									id : "companyEatApplyOrder_deliveryTimes",
									xtype : 'localcommonbox',
									anchor : '100%',
									width : 120,
									allowBlank : false,
									blankText : "配送时间段不能为空!",
									hiddenName : 'deliveryTimes',
									loaclarr : [['10:00~12:00', '10:00~12:00'],
											['12:00~14:00', '12:00~14:00'],
											['14:00~16:00', '14:00~16:00'],
											['16:00~18:00', '16:00~18:00']]

								}]

					}]
				}]
			});
	var d = new Ext.Window({
		id : "companyApplyEatVillageView",
		title : title,
		width : 500,
		height : 500,
		modal : true,
		layout : "fit",
		plain : true,
		items : [b, companyEatApplyOrderForm],
		buttonAlign : "center",
		buttons : [{
			text : "保存",
			handler : function() {
				var goodsId = b.getValue().toString();
				if (!goodsId) {
					Ext.MessageBox.show({
								title : "警告提示",
								msg : "请选择商品信息",
								buttons : Ext.MessageBox.WARNING,
								icon : Ext.MessageBox.WARNING
							});
					return;
				}
				//配送日期不为空校验
				//将deliveryDate格式转换为Y-m-d
				var deliveryDate = Ext.util.Format.date(Ext
								.getCmp("companyEatApplyOrder_deliveryDate")
								.getValue(), 'Y-m-d');

				if (!deliveryDate) {
					Ext.MessageBox.show({
								title : "警告提示",
								msg : "请选择配送日期",
								buttons : Ext.MessageBox.WARNING,
								icon : Ext.MessageBox.WARNING
							});
					return;
				}
				//配送时间段不为空校验

				var deliveryTimes = Ext
						.getCmp("companyEatApplyOrder_deliveryTimes")
						.getValue();
				if (!deliveryTimes) {
					Ext.MessageBox.show({
								title : "警告提示",
								msg : "请选择配送时间段",
								buttons : Ext.MessageBox.WARNING,
								icon : Ext.MessageBox.WARNING
							});
					return;
				}

				Ext.Msg.confirm("提示框", "确认申请试吃下单吗？", function(button) {
					if (button == "yes") {
						var optionMask = new Ext.LoadMask(Ext.getBody(), {
									msg : "正在处理,请稍后..."
								});
						optionMask.show();
						Ext.Ajax.request({
							url : __ctxPath
									+ "/companyEatApplyManager/companyEatApplyOrderPass",
							method : "POST",
							params : {
								id : id,
								goodsPriceSizeId : b.getValue().toString(),
								deliveryDate : deliveryDate,
								deliveryTimes : deliveryTimes
							},
							success : function(response, options) {

								optionMask.hide();

								var jsonData = Ext.util.JSON
										.decode(response.responseText);
								if (jsonData.success) {
									var gridPanel = Ext
											.getCmp('companyEatApplyOrderManagerGrid');
									if (typeof(gridPanel) != 'undefined') {
										gridPanel.store.reload();
									}
									Ext.MessageBox.show({
												title : "信息提示",
												msg : jsonData.data,
												buttons : Ext.MessageBox.OK,
												icon : Ext.MessageBox.INFO
											});
									queryCompanyEatApplyReview();
									d.close();
								} else {
									Ext.MessageBox.show({
												title : "错误提示",
												msg : jsonData.data,
												buttons : Ext.MessageBox.OK,
												icon : Ext.MessageBox.ERROR
											});
								}
							},
							failure : function(response, options) {
								optionMask.hide();
								Ext.MessageBox.show({
											title : "操作信息",
											msg : "服务器请求异常，请稍后再试!",
											buttons : Ext.MessageBox.OK,
											icon : Ext.MessageBox.ERROR
										});
							},
							scope : this
						});
					}

				});

			}
		}, {
			xtype : "tbseparator"
		}, {
			text : "取消",
			handler : function() {
				d.close();
			}
		}]
	});

	return d;

};